package com.tiancheng.trade.order.channel;


import com.tiancheng.trade.commom.core.enums.PaymentChannelEnum;
import com.tiancheng.trade.commom.core.exception.BusinessException;
import com.tiancheng.trade.commom.core.exception.error.BusinessErrorInfoEnum;
import com.tiancheng.trade.order.channel.apple.ApplePayChannel;
import com.tiancheng.trade.order.channel.cmb.CmbPayChannel;
import com.tiancheng.trade.order.channel.gaocheng.GcPayChannel;
import com.tiancheng.trade.order.channel.lklpay.LklPayOrderChannel;
import com.tiancheng.trade.order.channel.ums.UmsPayChannel;
import com.tiancheng.trade.commom.core.utils.ServiceLocator;
import com.tiancheng.trade.order.channel.umsdhjt.UmsDhjtPayChannel;
import com.tiancheng.trade.order.channel.umsmop.UmsMopPayChannel;
import com.tiancheng.trade.order.channel.umsshop.UmsShopPayChannel;

import java.util.HashMap;
import java.util.Map;

/**
 * 支付渠道工厂
 *
 * @author kellen
 * @date 2024/4/16
 */
public class PayChannelFactory {

    private static Map<String, Class> payChannelMap = new HashMap<>();

    static {
        payChannelMap.put(PaymentChannelEnum.CMB.getCode(), CmbPayChannel.class);
        payChannelMap.put(PaymentChannelEnum.UMS.getCode(), UmsPayChannel.class);
        payChannelMap.put(PaymentChannelEnum.APPLE.getCode(), ApplePayChannel.class);
        payChannelMap.put(PaymentChannelEnum.UMS_DHJT.getCode(), UmsDhjtPayChannel.class);
        payChannelMap.put(PaymentChannelEnum.UMS_MOP.getCode(), UmsMopPayChannel.class);
        payChannelMap.put(PaymentChannelEnum.gao_cheng_nong_hang.getCode(), GcPayChannel.class);
        payChannelMap.put(PaymentChannelEnum.UMS_SHOP.getCode(), UmsShopPayChannel.class);
        payChannelMap.put(PaymentChannelEnum.lkl_pay.getCode(), LklPayOrderChannel.class);
    }

    /**
     * 获取支付渠道
     * @param channel
     * @return
     * @throws BusinessException
     */
    public static AbstractPayChannel get(String channel) throws BusinessException {
        BusinessErrorInfoEnum.CHANNEL_NO_MATCH.assertIsTrue(payChannelMap.containsKey(channel));
        return (AbstractPayChannel) ServiceLocator.getBean(payChannelMap.get(channel));
    }
}
